package ssm.service;

import com.mysql.jdbc.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import ssm.dao.Track;
import ssm.dao.TrackWifi;
import ssm.model.TrackMapper;
import ssm.model.TrackWifiMapper;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class TrackWifiServiceImpl implements TrackWifiService {
    @Autowired
    private TrackWifiMapper trackWifiMapper;
    @Autowired
    private TrackMapper trackMapper;

    public List<TrackWifi> get() {
        List<TrackWifi> wifis = trackWifiMapper.get();
        return wifis;
    }

    public Map<String,Object> getByTimeOrJid(List<String> list, String jid, String starttime, String endtime, Integer page, Integer pageNum,Integer lx,String name) {
        Map<String, Object> result = new HashMap<String, Object>();
        Map<String, Object> param = new HashMap<String, Object>();
        if (jid != null &&!jid.equals("")) {
            param.put("jid", jid);
        }
        if (name != null && !name.equals("")) {
            param.put("name", name);
        }
        if (!list.isEmpty()) {
            param.put("list", list);
        }
        if (page != -1 && pageNum != 0) {
            int pageStart=(page)*pageNum;
            param.put("pageStart", pageStart);
            param.put("pageEnd", pageNum);
        }
       if(StringUtils.isNullOrEmpty(jid)&&StringUtils.isNullOrEmpty(name)){
           if(lx!=null&&!"".equals(lx)){
               param.put("lx",lx);
           }
       }
        param.put("starttime", starttime);
        param.put("endtime", endtime);
        List<Track> wifis = trackMapper.getWifi(param);
        result.put("data",wifis);
        int total=trackMapper.getWifiTotal(param);
        result.put("total",total);
        return result;
    }

    public TrackWifi getWifiByLsh(String lsh) {
        TrackWifi wifi = trackWifiMapper.getWifiByLsh(lsh);
        return wifi;
    }
}
